package com.sita.tingterest.adapter;

import android.app.Activity;
import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sita.bike.R;
import com.sita.tingterest.pojo.Music;

import java.util.ArrayList;

/**
 * Created by nilesh on 11/7/2015.
 */
public class MusicListViewAdapter extends BaseAdapter {


    private Activity activity;
    private Context context;
    private ArrayList<Music> MusicList = null;
    private int mPlayingPosition;

    public MusicListViewAdapter(FragmentActivity activity, ArrayList<Music> musicList) {
        this.activity = activity;
        this.MusicList = musicList;

    }

    public void setPlayingPosition(int position) {
        mPlayingPosition = position;
    }

    public int getPlayingPosition() {
        return mPlayingPosition;
    }

    public MusicListViewAdapter(Activity activity, ArrayList<Music> musicList) {
        this.activity = activity;
        this.MusicList = musicList;

    }

    public MusicListViewAdapter(ArrayList<Music> musicLists) {
        this.MusicList = musicLists;
    }

    @Override
    public int getCount() {

        Log.i("MY TAG", "MusicList.size();" + MusicList.size());

        return MusicList.size();
    }

    @Override
    public Object getItem(int position) {
        return MusicList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    public static class ViewHolder {
        //public ImageView img;
        public TextView txtViewTitle;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder view = null;
        LayoutInflater inflator = activity.getLayoutInflater();
        if (convertView == null) {
            view = new ViewHolder();
            convertView = inflator.inflate(R.layout.ting_list_row, null);

            view.txtViewTitle = (TextView) convertView.findViewById(R.id.title_song);
            // view.img = (ImageView) convertView.findViewById(R.id.pic);
            convertView.setTag(view);
        } else {
            view = (ViewHolder) convertView.getTag();

        }
        // Log.i("MY TAG","MusicList.get(position).getAuthorId()"+MusicList.get(position).getAuthorId());
        view.txtViewTitle.setText(MusicList.get(position).getTitle());
        //Log.i("MY TAG", "MusicList.get(position). getImage()" + MusicList.get(position).getImage());

        //new GetImage(view,convertView ).execute(MusicList.get(position).getPic().getUrl());


        return convertView;
    }
}
